package com.hsq.java.lambda;

import org.junit.jupiter.api.Test;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author hsq
 * @date 2025-07-01 下午1:18
 */
public class Interview {
    public static void main(String[] args) {

    }

    public List<String> myselfSplit(String str, String spe) {
        ArrayList<String> result = new ArrayList<>();
        int speLen = spe.length();
        int start = 0;
        int end = str.indexOf(spe, start);
        while (end != -1) {
            result.add(str.substring(start, end));
            start = end + speLen;
            end = str.indexOf(spe, start);
        }
        result.add(str.substring(start));
        return result;
    }

    public String myselfJoin(List<String> stringList, String spe) {
        String result = "";
        for (int i = 0; i < stringList.size(); i ++) {
            if (i == stringList.size() - 1) {
                result += stringList.get(i);
            } else {
                result += stringList.get(i) + spe;
            }
        }
        return result;
    }

    public Integer question2(List<Integer> list) {
        int sz = list.size();

        int[] count = new int[sz];
        int result = -1;

        for (int num : list) {
            count[num]++;
            if (count[num] == 2) {
                result = num;
                break;
            }
        }
        return result;
    }

    public void question3() {
        char[] letters = new char[26];
        for (int i = 0; i < 26; i++) {
            letters[i] = (char) ('a' + i);
        }

        long total = (1L << 26) - 1;
        System.out.println("26个字母的非空组合总数：" + total);
        List<StringBuilder> result = new ArrayList<>();
        for (long mask = 1; mask <= total; mask++) {
            StringBuilder subset = new StringBuilder();
            for (int i = 0; i < 26; i++) {
                if ((mask & (1L << i)) != 0) {
                    subset.append(letters[i]);
                }
                result.add(subset);
            }
        }
    }

    @Test
    public void test1() {
        String str = "ab&&2";
        String spe = "&&";
        List<String> list = myselfSplit(str, spe);
        System.out.println(list);
        String s = myselfJoin(list, spe);
        System.out.println(s);
        List<Integer> nums = new ArrayList<>();
        for (int i = 0; i < 999; i++) {
            nums.add(i);
        }
        nums.add(123);
        System.out.println(question2(nums));
        question3();



    }

}
